package mpcc.mpcc.activity.account_manage;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import mpcc.mpcc.activity.MPCCActivity;
import mpcc.mpcc.activity.R;
import mpcc.mpcc.activity.busi_presentation.AllBusinessActivity;
import mpcc.mpcc.activity.busi_presentation.NewsListActivity;
import mpcc.mpcc.activity.card_info.LoginActivity;
import mpcc.mpcc.base.BaseActivity;
import mpcc.mpcc.base.BaseInfo;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class BankListActivity extends BaseActivity {
	private List<Map<String, Object>> mData;
	private String toCardnum;
	private Button banklistReturn;
	private ListView bankListView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.banklist);
		bankListView = (ListView) findViewById(R.id.bankListView);
		banklistReturn = (Button) findViewById(R.id.banklistReturn);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		String requestStr = "22100003" + sdf.format(new Date());
		toCardnum = "";
		generateData();
		BaseAdapter adapter = new MyAdapter(this);
		bankListView.setAdapter(adapter);
		bankListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View v, int position,
					long arg3) {
				String bankid = (String) mData.get(position).get("bankid");
				showInfo(bankid);

			}

		});
		addChangeActListener(banklistReturn,this,AccountManageActivity.class);
				
			

	}

	public void generateData() {

		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("bankName", "1");
		map.put("bankImage", R.drawable.aa);
		map.put("bankid", "1");
		list.add(map);
		map = new HashMap<String, Object>();
		map.put("bankName", "2");
		map.put("bankImage", R.drawable.aa);
		map.put("bankid", "2");
		list.add(map);
		map = new HashMap<String, Object>();
		map.put("bankName", "3");
		map.put("bankImage", R.drawable.aa);
		map.put("bankid", "3");
		list.add(map);
		setmData(list);
	}

	public void setmData(List<Map<String, Object>> mData) {
		this.mData = mData;
	}

	public void showInfo(String bankid) {
		ArrayList<String> arrClass = new ArrayList<String>();
		arrClass.add(bankid);
		arrClass.add(toCardnum);
		Bundle bundle = new Bundle();
		bundle.putSerializable("chargelist", arrClass);

		Intent intent = new Intent();
		intent.putExtras(bundle);
		intent.setClass(this, ChargeActivity.class);
		startActivity(intent);

	}

	public final class ViewHolder {
		public TextView bankName;
		public ImageView bankImage;
	}

	public class MyAdapter extends BaseAdapter {

		private LayoutInflater mInflater;

		public MyAdapter(Context context) {
			this.mInflater = LayoutInflater.from(context);
		}

		public int getCount() {
			return mData.size();
		}

		public Object getItem(int arg0) {
			return null;
		}

		public long getItemId(int arg0) {
			return 0;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder holder = null;
			if (convertView == null) {
				holder = new ViewHolder();
				convertView = mInflater.inflate(R.layout.elebank, null);
				holder.bankName = (TextView) convertView
						.findViewById(R.id.bankName);
				holder.bankImage = (ImageView) convertView
						.findViewById(R.id.bankImage);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			holder.bankName.setText((String) mData.get(position)
					.get("bankName"));
			holder.bankImage.setImageResource((Integer) mData.get(position)
					.get("bankImage"));
			return convertView;
		}
	}
}
